package com.example.mall.web.controller;

import com.example.mall.domain.SystemPerformance;
import com.example.mall.dto.SystemPerformanceDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SystemPerformanceQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISystemPerformanceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemPerformance")
public class SystemPerformanceController {

    @Autowired
    public ISystemPerformanceService systemPerformanceService;

    /**
     * 分页查询系统性能监控表信息
     * @param systemPerformanceQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询系统性能监控表信息",notes = "分页查询系统性能监控表信息",httpMethod = "GET")
    public JSONResult queryPage(SystemPerformanceQuery systemPerformanceQuery){
        PageDTO<SystemPerformanceDto> systemPerformanceDtoPageDTO = systemPerformanceService.queryPage(systemPerformanceQuery);
        return JSONResult.success("查询成功",systemPerformanceDtoPageDTO);
    }

    /**
     * 根据id查询系统性能监控表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询系统性能监控表信息",notes = "根据id查询系统性能监控表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SYSTEM_PERFORMANCEID_NOT_ID);
        }
        SystemPerformance systemPerformance = systemPerformanceService.getById(id);
        return JSONResult.success("查询成功",systemPerformance);
    }

    /**
     * 根据id查询系统性能监控表信息
     * @param id
     * @return
     */
    @GetMapping("querySystemPerformanceById/{id}")
    @ApiOperation(value = "根据id查询系统性能监控表信息",notes = "根据id查询系统性能监控表信息",httpMethod = "GET")
    public JSONResult querySystemPerformanceById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SYSTEM_PERFORMANCEID_NOT_ID);
        }
        SystemPerformance systemPerformance = systemPerformanceService.querySystemPerformanceById(id);
        return JSONResult.success("查询成功",systemPerformance);
    }

    /**
     * 查询全部系统性能监控表信息
     * @param
     * @return
     */
    @GetMapping("querySystemPerformanceList")
    @ApiOperation(value = "查询全部系统性能监控表信息",notes = "查询全部系统性能监控表信息",httpMethod = "GET")
    public JSONResult querySystemPerformanceList(){
        List<SystemPerformance> systemPerformances = systemPerformanceService.querySystemPerformanceList();
        return JSONResult.success("查询成功",systemPerformances);
    }

    /**
     * 新增系统性能监控表
     * @param systemPerformanceDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增系统性能监控表",notes = "新增系统性能监控表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SystemPerformanceDto systemPerformanceDto){
        systemPerformanceService.insert(systemPerformanceDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改系统性能监控表信息
     * @param systemPerformanceDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改系统性能监控表信息",notes = "修改系统性能监控表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SystemPerformanceDto systemPerformanceDto){
        systemPerformanceService.update(systemPerformanceDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除系统性能监控表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除系统性能监控表信息",notes = "删除系统性能监控表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        systemPerformanceService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除系统性能监控表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除系统性能监控表信息",notes = "批量删除系统性能监控表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        systemPerformanceService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
